/* Copyright (c) 2010, David Kreuter. See LICENSE for more information */

#ifndef IN_HEADERS_H
#error This file should be included through "headers.h"
#endif

typedef struct _mdl_foo{
	char name[17];
	uint32 offset;
}mdl_foo;

typedef mdl_foo mdl_tex;
typedef mdl_foo mdl_pal;

typedef struct mdl_obj{
	char name[17];
	uint32 offset;
	// THESE PARAMETERS ARE IGNORED FOR NOW
	uint8  srt;          // Scale, Rotate, Translate flags in BMD-Format
	uint16 scale;        // 4.12
	uint16 rot[2];       // 4.12
	uint16 translate[3]; // 4.12
}mdl_obj;

typedef struct _mdl_mat{
	char name[17];
	uint32 offset;

	uint8 repeat;
	uint8 pal_id;
	uint8 tex_id;
	uint16 gl_id;
}mdl_mat;

typedef struct _mdl_vert{
	float col[3];
	float pos[3];
	float uv[2];
}mdl_vert;

typedef mdl_vert mdl_tri[3];
typedef mdl_vert mdl_quad[4];

typedef struct _mdl_layer{
	char name[17];
	uint32 offset;
	uint8  mat_id;
	uint16  tri_offset;
	uint16 quad_offset;
	uint16 num_tris;
	uint16 num_quads;
}mdl_layer;

typedef struct _mdl{
	uint32 len; // For developing reasons! Delete in stable-version!
	char name[17];
	float scale;
	uint8  num_mats;
	uint8  num_texs;
	uint8  num_pals;
	uint16 num_tris;
	uint16 num_quads;
	uint8  num_layers;
	uint8  num_objs;
	mdl_mat   *mat;
	mdl_tex   *tex;
	mdl_pal   *pal;
	mdl_tri   *tri;
	mdl_quad  *quad;
	mdl_layer *layer;
	mdl_obj   *obj;
}mdl;

int process3d_do(uint8 *, uint32, mdl *, mdl_layer *);
mdl *read_mdl(uint8 *, uint32);
int write_mdl(mdl *, uint8 *, uint32);
void free_mdl(mdl *);
uint32 size_mdl(mdl *);
